package org.example.MQ;

import java.util.Date;
import java.util.concurrent.BlockingDeque;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit;

public class Consumer implements Runnable{
    private BlockingQueue<Data> queue;

    public Consumer(BlockingQueue<Data> queue) {
        this.queue = queue;
    }
    @Override
    public void run() {
        while (true){
            //获取数据
            try {
                Data data = this.queue.take();
                TimeUnit.MILLISECONDS.sleep(ThreadLocalRandom.current().nextInt(1000));
                System.out.println("当前消费线程:"+Thread.currentThread().getName() +"消费成功，消费id为:"+ data.getId());
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }

        }
    }
}
